<html>
<head><meta charset="utf-8"><title>Unconstrained const parameters · t-lang/doc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/index.html">t-lang/doc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html">Unconstrained const parameters</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222205599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222205599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222205599">(Jan 10 2021 at 04:38)</a>:</h4>
<p>@ehuss I did the research and figured it out. The gist of it is that while other items allow unused const parameters (effectively phantom const parameters), <code>impl</code> does not.</p>



<a name="222205616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222205616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222205616">(Jan 10 2021 at 04:39)</a>:</h4>
<p>The previous PR says that its types that allow unconstrained const params, but <code>fn</code> and <code>trait</code> allow them too: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=55a658fb283e0e7dd4b7ffc9a2689b5c">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=55a658fb283e0e7dd4b7ffc9a2689b5c</a></p>



<a name="222205681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222205681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222205681">(Jan 10 2021 at 04:41)</a>:</h4>
<p>It doesn't directly affect your current PR, but you may want to add this change to it? I'm willing to r+ your current PR if we want to do this in a separate PR (which I can write if you want)</p>



<a name="222205895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222205895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222205895">(Jan 10 2021 at 04:48)</a>:</h4>
<p>Yea, I think the term "type" wasn't precise, and I can clarify that.</p>
<p>The higher question was how should <a href="https://github.com/rust-lang/reference/blob/master/src/items/implementations.md#generic-implementations">https://github.com/rust-lang/reference/blob/master/src/items/implementations.md#generic-implementations</a> be updated?  Just change the second sentence to "Type and const parameters…must be used at least once…"?</p>
<p>It looks like lifetimes don't have to be used in an impl, which is weird.</p>



<a name="222205949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222205949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222205949">(Jan 10 2021 at 04:50)</a>:</h4>
<p>I was uncertain if "constrained" is a technical term with specific meaning that is more elaborate than "used".</p>



<a name="222206084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206084">(Jan 10 2021 at 04:55)</a>:</h4>
<p>I think "constrained" does have more meaning.  This example "uses" the type parameter in the predicate, but it is still unconstrained:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">T</span>: <span class="nb">PartialEq</span> <span class="p">{}</span><span class="w">  </span><span class="c1">// ERROR: T is not constrained</span>
</code></pre></div>



<a name="222206090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206090">(Jan 10 2021 at 04:55)</a>:</h4>
<p>So I don't know how to define the word "constrained" correctly.</p>



<a name="222206141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206141">(Jan 10 2021 at 04:56)</a>:</h4>
<p>Constrained means that the parameter is used to select a specific monomorphization. "Used" basically sums it up. If we want to be precise, I'd be okay with a parenthetical "constrained (used)" and you know how much I'm normally against them.</p>



<a name="222206155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206155">(Jan 10 2021 at 04:57)</a>:</h4>
<p><span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="222206198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206198">(Jan 10 2021 at 04:58)</a>:</h4>
<p><code>T</code> doesn't constrain <code>S</code> in your example, because it doesn't, uhhh, connect to <code>S</code> in any way.</p>



<a name="222206214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206214">(Jan 10 2021 at 04:59)</a>:</h4>
<p>Ah, I see this comment about lifetimes: <code>Disallow unconstrained lifetimes, but only if they appear in assoc types.</code>   I wonder why…</p>



<a name="222206217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206217">(Jan 10 2021 at 04:59)</a>:</h4>
<p>The comment also mentions backwards compatibility and unhygenic macros.</p>



<a name="222206264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206264">(Jan 10 2021 at 05:00)</a>:</h4>
<p>ah..., a footnote <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="222206275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206275">(Jan 10 2021 at 05:01)</a>:</h4>
<p>It's getting pretty late where I am.  I'll try to look at fixing these up tomorrow.</p>



<a name="222206321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206321">(Jan 10 2021 at 05:02)</a>:</h4>
<p>If you want, I can send a PR against your branch tonight.</p>



<a name="222206322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206322">(Jan 10 2021 at 05:02)</a>:</h4>
<p>Yea, if you'd like, that would be great!</p>



<a name="222206520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222206520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222206520">(Jan 10 2021 at 05:08)</a>:</h4>
<p><em>cracks fingers</em></p>



<a name="222210049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222210049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222210049">(Jan 10 2021 at 07:08)</a>:</h4>
<p>OMG, _why_ _why_ _why_?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// compiles</span>
<span class="k">impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">HasAssocType</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Struct</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Struct</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// Error: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates</span>
<span class="k">impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">HasAssocType</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Struct</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="n">Struct</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="222213630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222213630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222213630">(Jan 10 2021 at 09:12)</a>:</h4>
<p>In the first case <code>'a</code> is simply unused, so it doesn't matter what the used lifetime is. In the second case it is used but not constrained, so it is unknown what to use.</p>



<a name="222217566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222217566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222217566">(Jan 10 2021 at 11:12)</a>:</h4>
<p>So, I kinda had to leave the computer for a bit after I saw that, and actually watched TV for the first time in over a year. I need to add it to my work, but it's now 3am and I'm going to bed. The good news is that most of this work is actually about documenting constraining at all and constants act almost entirely like type parameters, so I see no reason to care about it in the const generics documentation other than that one line which might as well be done with the defining of constraining.</p>



<a name="222264037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/237824-t-lang/doc/topic/Unconstrained%20const%20parameters/near/222264037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/237824-t-lang/doc/topic/Unconstrained.20const.20parameters.html#222264037">(Jan 11 2021 at 06:34)</a>:</h4>
<p>Just finished my writing on constraining.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>